import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import uic
from Test import flir_camera
import numpy as np
from PyQt5.QtCore import QElapsedTimer
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        uic.loadUi('graphicsshow.ui', self)
        self.scene = QGraphicsScene(self)
        self.elapsedTime = QElapsedTimer()
        self.count = 0
        try:
            flir_camera.initSystem()
            print('系统初始化')
            self.visionCamera = flir_camera.Cam()
            print('相机初始化')
            self.visionCamera.imageArrived.connect(self.onReceiveImage)
            print('接收初始化')
            self.visionCamera.enableAcquisition()
            print('接收开关打开')
            self.elapsedTime.start()
        except:
            print('error')
            pass


    @pyqtSlot(np.ndarray, int)
    def onReceiveImage(self, image, count):
        print(count)
        qimage = QImage(image.data, image.shape[1], image.shape[0], QImage.Format_RGB888)
        pix = QPixmap.fromImage(
                qimage.scaled(
                    self.ImageBox.size(),
                    Qt.KeepAspectRatio,
                    Qt.SmoothTransformation
                )
            )
        item = QGraphicsPixmapItem(pix)
        self.scene.addItem(item)
        self.ImageBox.setScene(self.scene)

        elapsed = self.elapsedTime.elapsed()
        self.count += 1
        print(self.count/(elapsed*0.001))




if __name__ == '__main__':
    app = QApplication(sys.argv)
    # #print(QStyleFactory.keys())
    app.setStyle('Fusion')
    wnd = MainWindow()
    wnd.setGeometry(
        QStyle.alignedRect(
            Qt.LeftToRight,
            Qt.AlignCenter,
            wnd.size(),
            app.desktop().availableGeometry()
        )
    )
    print('1')
    wnd.show()
    sys.exit(app.exec_())